package com.yanqu.road.server.cmd.activity.peakstronghold.cross;

import com.yanqu.road.entity.activity.peakstronghold.config.PeakStrongHoldConfig;
import com.yanqu.road.entity.activity.peakstronghold.config.PeakStrongholdDonateConfig;
import com.yanqu.road.entity.log.LogPeakHoldItemDonate;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.PeakStrongholdWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.peakstronghold.PeakStrongholdActivityMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

@Cmd(code = GameProtocol.S_PEAK_STRONGHOLD_ITEM_DONATE_CROSS_BACK, desc = "捐献返回")
public class CrossPeakStrongholdItemDonateBackCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        PeakStrongHoldConfig config = PeakStrongholdActivityMgr.getConfig();
        if (null == config) {
            return;
        }
        PeakStrongholdWarProto.CrossPeakHoldItemDonateResp msg = PeakStrongholdWarProto.CrossPeakHoldItemDonateResp.parseFrom(packet.getBytes());
        int donateId = msg.getDonateId();
        PeakStrongholdDonateConfig donateConfig = config.getDonateConfigMap().get(donateId);
        if (null == donateConfig) {
            return;
        }
        Property cost = PropertyHelper.parseStringToProperty(donateConfig.getConsume());
        cost.goodCountMultiNum(msg.getDonateNum());
        int expAdd = donateConfig.getExp() * msg.getDonateNum();

        AutoLogMgr.add(new LogPeakHoldItemDonate(msg.getActivityId(), msg.getRound(), packet.getPlayerId(), msg.getDonateId(),
                PropertyHelper.parsePropertyToString(cost), msg.getRewards(), msg.getDonateNum(), expAdd, msg.getBeforeTotalExp(), msg.getAfterTotalExp()));
    }

    @Override
    public void sendData(GamePlayer player) {
    }
}
